package itheima.lianxi1;

public class ShuZuQuChong {
    public static void main(String[] args) {
        int[] arr = {1,2,3,4,2,3,3,3,3,3,0,4,0,0,5,6,3,2,5,2,1,1};
        //定义一个相同长度的数组
        boolean[] b = new boolean[arr.length];  //[f,f,f,f,f,f,f,f,f]
        for (int i = 0; i < arr.length - 1; i++) {
            //
            for (int i1 = i + 1; i1 < arr.length; i1++) {

                //判断当前i索引对应的元素和后面所有元素比较
                if (arr[i] == arr[i1]){
                    b[i1] = true;
                    break;
                }
            }
        }

        //定义一个计数器统计新数组长度
        int count = 0;

        for (int i = 0; i < b.length; i++) {
            if (b[i] == false){
                count++;
            }
        }

        //定义能存放去重之后的数组
        int[] x = new int[count];  // [0,0,0,0,0,0]
        //定义变量代表新数组的索引
        int y = 0;
        //
        for (int i = 0; i < b.length; i++) {
            //判断索引是有为false，是就存入新数组
            if (b[i] == false){
                x[y] = arr[i];
                //存储一次y后移一次
                y++;
            }
        }
    }
}
